<?php 
// error_reporting(0);
define('PATH', substr(dirname(__FILE__),0,-13));
$cfg_config = include PATH . '/config/config.php';
include PATH . '/core/Mysql.class.php';


$size = 2 ;
$start = isset($argv[1])?$argv[1]:0;


$db = new dbQuery($cfg_config['mysql']['hostname'], $cfg_config['mysql']['username'], $cfg_config['mysql']['password'], $cfg_config['mysql']['database']);
$db->connect($cfg_config['mysql']['hostname'], $cfg_config['mysql']['username'], $cfg_config['mysql']['password'], $cfg_config['mysql']['database']);
$redis = new Redis();
$redis -> connect($cfg_config['redis']['server'], 6379);
$redis -> select($cfg_config['redis']['main_key']); 
// 查询最大的kid 并载入缓存
$sql = "SELECT MAX(kid) FROM `video_keys` ";
$rr = $db -> query($sql);
$row = $db -> fetch_array($rr);
$max_kid = $row['MAX(kid)'];
$redis -> set('max_kid', $max_kid);

while (true) {
	$sql = "select * from `video_keys` where  `kid`> $start ORDER BY `kid` ASC  limit $size" ;
	$rr = $db -> query($sql);
	if ($db -> affected_rows($rr) == 0) {
		die("\n\n Over ... \n\n");
    } while ($row = $db -> fetch_array($rr)) {
        $redis -> set('V:'.$row['kid'], $row['py']);
        $kk = 'V:'.$row['kid'];
		$redis -> set($row['py'], $row['kid'] . '|' . $row['key']. '|' . $row['sgk']);
		$start = $row['kid'] ;
		echo "\r" . $row['kid'] ;
	}
} 

?>
